﻿using System;
using System.Globalization;
using System.IO;
using System.Windows;
using System.Windows.Resources;

using SilverBullet.Manifest;

namespace Microsoft.Xna.Framework
{
	/// <summary>
	/// Provides file stream access to the title's default storage location.
	/// </summary>
	public static class TitleContainer
	{
		/// <summary>
		/// Returns a stream to an existing file in the default title storage location.
		/// </summary>
		/// <param name="name">The name of the file to open.</param>
		/// <exception cref="System.IO.FileNotFoundException">The file specified by <paramref name="name"/> could not be found.</exception>
		public static Stream OpenStream(string name)
		{
			string path = name.Replace('\\', '/');
			path = String.Format("/{0};component/{1}", Discovery.EntryPointAssembly, name);
			StreamResourceInfo info = Application.GetResourceStream(new Uri(path, UriKind.Relative));

			if (info == null)
				throw new FileNotFoundException(string.Format(CultureInfo.CurrentCulture, FrameworkResources.OpenStreamNotFound, name));

			return info.Stream;
		}
	}
}
